package com.asianrapid.controller.sys;

import com.asianrapid.model.sys.LampEntity;
import com.asianrapid.model.sys.PageResult;
import com.asianrapid.service.sys.LampService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class LampController {
    private Logger log = LoggerFactory.getLogger(LampController.class);

    @Autowired
    private LampService lampService;

    @GetMapping("/lamps")
    public PageResult getAllLamps(int pageSize, int page){

        PageResult pageResult = new PageResult();
        pageResult.setData(lampService.lampsList( pageSize,page * pageSize ));
        pageResult.setTotalCount(lampService.lampsSize( pageSize,page * pageSize ));
        log.debug("The method is ending");

        return pageResult;

    }/*getLamp*/



    @PostMapping("/zgr")
    public LampEntity getLamps(@RequestBody List<Integer> groupId){

        return lampService.getLamp(groupId.get(0));

    }



    @PostMapping("/menus/lamp")
    public void insertLamp(@RequestBody LampEntity lampEntity ){
        lampService.insertLamp(lampEntity);
    }



    @PutMapping("/lamp/{id}")
    public LampEntity updateLamp(@RequestBody LampEntity lampEntity, @PathVariable int id) {
        if (lampEntity.getId() == id) {
            lampService.updateLamp(lampEntity);
        }
        log.debug("The method is ending");
        return lampEntity;
    }/*delLamp*/



    @DeleteMapping("/delLamp")
    public List<String> deleteLamp(@RequestBody List<String> groupId) {
        lampService.deleteLamp(groupId);
        return groupId;
    }

}
